package com.springboot.last_experiment.controller;

import com.springboot.last_experiment.entity.Health;
import com.springboot.last_experiment.service.HealthService;
import com.springboot.last_experiment.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class HealthController {

    @Autowired
    HealthService healthService;

    /**
     * 添加健康信息
     * @param health
     * @return
     */
    @PostMapping("/health")
    public ResultVO addInfo(Health health, @RequestParam("skey") String skey){
        return healthService.health_insert(health,skey);
    }

    /**
     * 查询所有
     * @return
     */
    @GetMapping("/healths")
    public ResultVO getAllInfo(){
        return healthService.getAllHea();
    }

    /**
     *查询某个健康信息
     * @param id
     * @return
     */
    @GetMapping("/health/{id}")
    public ResultVO getHeaById(@PathVariable("id") Integer id){
        return healthService.getHeaById(id);
    }

    /**
     * 搜索：根据进出查询，或根据状态查询
     * @param key
     * @return
     */
    @GetMapping("/healths/{k}")
    public ResultVO getAdmByKey(@PathVariable("k") String key){
        return healthService.getHeaByKey(key);
    }

    /**
     * 修改健康信息
     * @param health
     * @return
     */
    @PutMapping("/health")
    public ResultVO update(Health health){
        return healthService.updateHea(health);
    }

    /**
     * 查询所有状态为预警的用户
     * @return
     */
    @GetMapping("/healths/warn")
    public ResultVO getWarn(){
        return healthService.getWarn();
    }

    /**
     * 查询所有状态为高危的用户
     * @return
     */
    @GetMapping("/healths/danger")
    public ResultVO getDanger(){
        return healthService.getDanger();
    }

    @GetMapping("/healths/byOpenid/{openid}")
    public ResultVO healthsByOpenid(@PathVariable ("openid") String openid){
        return healthService.getUserByOpenid(openid);
    }


}
